//菜品设置数据存放
import http from '../../../http/http'
import * as url from '../../../api/lypApi'
const state = {
  tableData:[],

};
const actions = {
  getData({commit}){
     return http({
      url:'/lypApi'+url.GETDISHE,
       method:"post",
      // url:'http://123.57.67.148:3000/mock/52/getDishes',
      // method:"get",
    }).then(res=>{
      console.log(res.data)
      this.tableData=res.data.list
      console.log(this.tableData)
       commit('addData',res.data.list)
    }).catch(err=>{
      console.log(err)
    })

  },
  deleteData({commit},obj){
    console.log(obj.classify)
    let delData=this.tableData.filter(item=> item.id!=obj.id)
    this.tableData=delData
    http({
      url:`/lypApi${url.DELDISHES}`,
      method:'post',
      data:{
        "id": obj.id,
      }
    }).then(res=>{
      console.log(res)
    }).catch(err=>{
      console.log(err)
    })
    commit('addData',delData)
  },
  selectData({dispatch,commit},obj){
    console.log(obj)
    // return dispatch('getData').then(() => {
    //   // commit('someOtherMutation')
    // })
    let selectData=[]
    this.tableData.forEach((item)=>{
      if (item[obj[0]]==obj[1]){
        console.log(item)
        selectData.push(item)
      }
    })
    return selectData
  }
};
const mutations = {
  addData(state,obj){
    state.tableData = obj
    console.log(this.tableData)
  }
}
const  getters= {

};
export default {
  state,
  actions,
  mutations,
  getters
}
